<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">Login</div>
      <el-form :model="param" ref="login" label-width="0px" class="ms-content">
        <el-form-item prop="username">
          <el-input v-model="param.username" placeholder="账号">
            <el-button slot="prepend" icon="el-icon-s-custom" style="font-size:20px"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            placeholder="密码"
            style="font-size:20px"
            v-model="param.password"
            @keyup.enter.native="submitForm()"
          >
            <el-button slot="prepend" icon="el-icon-view"></el-button>
          </el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="success" @click="submitForm()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import {getLogin} from "@/utils/login";
export default {
  data: function () {
    return {
      param: {
        username: "",
        password: "",
      },
    };
  },
  components: {},
  methods: {
    submitForm() {
      // this.$refs.login.validate((valid) => {
      //   if (valid) {
      //     this.$message.success("登录成功");
      //     localStorage.setItem("ms_username", this.param.username);
      //     this.$router.push("/");
      //   } else {
      //     this.$message.error("请输入账号和密码");
      //     console.log("error submit!!");
      //     return false;
      //   }
      // });
      getLogin(this.param.username,this.param.password).then((res)=>{
        if (res.code == 2000) {
          let token = res.data.token;
          localStorage.setItem("token", token);
          localStorage.setItem("user", this.param.username);
          this.$router.push({ path: "/" });
          this.$message.success("登录成功");
        } else {
          this.$message.error(res.msg);
        }
      })
    },
  },
};
</script>

<style scoped>
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url(../assets/img/loginbg.jpg);
  background-size: 100vw 100vh;
}
.ms-title {
  width: 100%;
  line-height: 50px;
  text-align: center;
  font-size: 48px;
  color: #fff;
}
.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 400px;
  border-radius: 5px;
  transform: translate(-50%, -25%);
  overflow: hidden;
}
.ms-content {
  padding: 30px 30px;
}
.login-btn {
  text-align: center;
}
.login-btn button {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}
.login-tips {
  font-size: 12px;
  line-height: 30px;
  color: #fff;
}
</style>